import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/closure/closure_appointment_entity.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

class TaskWaitingManagementController extends GetxController {
  /// 搜索使用key
  final GlobalKey<CustomEasyRefreshListState> globalKey = GlobalKey();

  // 获取数据
  Future<List<ClosureAppointmentEntity>> getListData(int pageNum, int pageSize, {String? search}) async {
    // 获取列表接口
    final res = await HttpUtil().generateGetRequest<List<ClosureAppointmentEntity>>(
      Interface.getWaitingList,
      queryParameters: {
        'pageNum': pageNum,
        'pageSize': pageSize,
        'cph': search,
        'waitingForInspectionStatus': 1,
      },
    ).execute();
    List<ClosureAppointmentEntity>? data;
    res.onSuccess((result) {
      if (result.data != null) {
        data = result.data!;
      }
    });
    return data ?? [];
  }

  void refreshPage() {
    globalKey.currentState?.onRefresh();
  }

  /// 进入审批详情页面
  void toApprovalDetailsPage(ClosureAppointmentEntity entity) {
    Get.toNamed(AppRoutes.waitingManagementApproval, arguments: entity);
  }
}
